package paneles;

import java.awt.CardLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Rectangle;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import java.awt.FlowLayout;

import javax.swing.border.SoftBevelBorder;
import javax.swing.border.BevelBorder;
import javax.swing.text.NumberFormatter;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
import java.awt.SystemColor;
import java.text.NumberFormat;

import javax.swing.JFormattedTextField;

@SuppressWarnings("serial")
public class panelRegistro extends JPanel {
	private JTextField txtNombre;
	private JButton btnRegistrarse;
	private JLabel lblNombre;
	private JLabel lblApellido;
	private JLabel lblApellido_1;
	private JPasswordField passwordField;
	private JLabel lblCorreoElectrnico;
	private JPanel panel;
	private JButton btnVolver;
	private JLabel lblContrasea;
	private JTextField txtA1;
	private JTextField txtA2;
	private JTextField txtCorreo;
	private JPasswordField passwordField_1;
	private JLabel lblRepitaContrasea;
	private JLabel label;
	private JLabel label_1;
	private JLabel label_2;
	private JLabel label_3;
	private JLabel label_4;
	private JLabel label_5;
	private JLabel lblTelfono;
	private JLabel label_6;
	private JLabel lblCampos;
	private JFormattedTextField txtTelefono;

	public panelRegistro(final JPanel cardLayout) {
		setBounds(new Rectangle(100, 100, 800, 600));
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[] { 0, 0, 335, 0, 0, 0, 0 };
		gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
		gridBagLayout.columnWeights = new double[] { 1.0, 0.0, 1.0, 0.0, 1.0, 0.0,
				Double.MIN_VALUE };
		gridBagLayout.rowWeights = new double[] { 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0,
				0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE };
		setLayout(gridBagLayout);
		
				JLabel lblCreaTuCuenta = new JLabel("Cree su cuenta");
				lblCreaTuCuenta.setForeground(SystemColor.textHighlight);
				lblCreaTuCuenta.setFont(new Font("Segoe UI", Font.PLAIN, 25));
				GridBagConstraints gbc_lblCreaTuCuenta = new GridBagConstraints();
				gbc_lblCreaTuCuenta.insets = new Insets(0, 0, 5, 5);
				gbc_lblCreaTuCuenta.gridx = 2;
				gbc_lblCreaTuCuenta.gridy = 1;
				add(lblCreaTuCuenta, gbc_lblCreaTuCuenta);

		lblNombre = new JLabel("Nombre:");
		lblNombre.setFont(new Font("Segoe UI", Font.PLAIN, 14));
		GridBagConstraints gbc_lblNombre = new GridBagConstraints();
		gbc_lblNombre.insets = new Insets(0, 0, 5, 5);
		gbc_lblNombre.anchor = GridBagConstraints.WEST;
		gbc_lblNombre.gridx = 1;
		gbc_lblNombre.gridy = 3;
		add(lblNombre, gbc_lblNombre);

		txtNombre = new JTextField();
		txtNombre.setFont(new Font("Segoe UI", Font.PLAIN, 14));
		txtNombre.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null,
				null, null, null));
		GridBagConstraints gbc_txtNombre = new GridBagConstraints();
		gbc_txtNombre.insets = new Insets(0, 0, 5, 5);
		gbc_txtNombre.fill = GridBagConstraints.HORIZONTAL;
		gbc_txtNombre.gridx = 2;
		gbc_txtNombre.gridy = 3;
		add(txtNombre, gbc_txtNombre);
		txtNombre.setColumns(10);
		
		label = new JLabel("(*)");
		label.setFont(new Font("Segoe UI", Font.PLAIN, 14));
		GridBagConstraints gbc_label = new GridBagConstraints();
		gbc_label.insets = new Insets(0, 0, 5, 5);
		gbc_label.gridx = 3;
		gbc_label.gridy = 3;
		add(label, gbc_label);

		lblApellido = new JLabel("Apellido Paterno:");
		lblApellido.setFont(new Font("Segoe UI", Font.PLAIN, 14));
		GridBagConstraints gbc_lblApellido = new GridBagConstraints();
		gbc_lblApellido.insets = new Insets(0, 0, 5, 5);
		gbc_lblApellido.anchor = GridBagConstraints.WEST;
		gbc_lblApellido.gridx = 1;
		gbc_lblApellido.gridy = 4;
		add(lblApellido, gbc_lblApellido);

		txtA1 = new JTextField();
		txtA1.setFont(new Font("Segoe UI", Font.PLAIN, 14));
		txtA1.setColumns(10);
		txtA1.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null,
				null, null, null));
		GridBagConstraints gbc_txtA1 = new GridBagConstraints();
		gbc_txtA1.insets = new Insets(0, 0, 5, 5);
		gbc_txtA1.fill = GridBagConstraints.HORIZONTAL;
		gbc_txtA1.gridx = 2;
		gbc_txtA1.gridy = 4;
		add(txtA1, gbc_txtA1);
		
		label_1 = new JLabel("(*)");
		label_1.setFont(new Font("Segoe UI", Font.PLAIN, 14));
		GridBagConstraints gbc_label_1 = new GridBagConstraints();
		gbc_label_1.insets = new Insets(0, 0, 5, 5);
		gbc_label_1.gridx = 3;
		gbc_label_1.gridy = 4;
		add(label_1, gbc_label_1);

		lblApellido_1 = new JLabel("Apellido Materno:");
		lblApellido_1.setFont(new Font("Segoe UI", Font.PLAIN, 14));
		GridBagConstraints gbc_lblApellido_1 = new GridBagConstraints();
		gbc_lblApellido_1.insets = new Insets(0, 0, 5, 5);
		gbc_lblApellido_1.anchor = GridBagConstraints.WEST;
		gbc_lblApellido_1.gridx = 1;
		gbc_lblApellido_1.gridy = 5;
		add(lblApellido_1, gbc_lblApellido_1);

		txtA2 = new JTextField();
		txtA2.setFont(new Font("Segoe UI", Font.PLAIN, 14));
		txtA2.setColumns(10);
		txtA2.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null,
				null, null, null));
		GridBagConstraints gbc_txtA2 = new GridBagConstraints();
		gbc_txtA2.insets = new Insets(0, 0, 5, 5);
		gbc_txtA2.fill = GridBagConstraints.HORIZONTAL;
		gbc_txtA2.gridx = 2;
		gbc_txtA2.gridy = 5;
		add(txtA2, gbc_txtA2);
		
		label_2 = new JLabel("(*)");
		label_2.setFont(new Font("Segoe UI", Font.PLAIN, 14));
		GridBagConstraints gbc_label_2 = new GridBagConstraints();
		gbc_label_2.insets = new Insets(0, 0, 5, 5);
		gbc_label_2.gridx = 3;
		gbc_label_2.gridy = 5;
		add(label_2, gbc_label_2);

		lblCorreoElectrnico = new JLabel("Correo Electr\u00F3nico:");
		lblCorreoElectrnico.setFont(new Font("Segoe UI", Font.PLAIN, 14));
		GridBagConstraints gbc_lblCorreoElectrnico = new GridBagConstraints();
		gbc_lblCorreoElectrnico.insets = new Insets(0, 0, 5, 5);
		gbc_lblCorreoElectrnico.anchor = GridBagConstraints.EAST;
		gbc_lblCorreoElectrnico.gridx = 1;
		gbc_lblCorreoElectrnico.gridy = 6;
		add(lblCorreoElectrnico, gbc_lblCorreoElectrnico);

		txtCorreo = new JTextField();
		txtCorreo.setFont(new Font("Segoe UI", Font.PLAIN, 14));
		txtCorreo.setColumns(10);
		txtCorreo.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null,
				null, null, null));
		GridBagConstraints gbc_txtCorreo = new GridBagConstraints();
		gbc_txtCorreo.insets = new Insets(0, 0, 5, 5);
		gbc_txtCorreo.fill = GridBagConstraints.HORIZONTAL;
		gbc_txtCorreo.gridx = 2;
		gbc_txtCorreo.gridy = 6;
		add(txtCorreo, gbc_txtCorreo);
				
				label_3 = new JLabel("(*)");
				label_3.setFont(new Font("Segoe UI", Font.PLAIN, 14));
				GridBagConstraints gbc_label_3 = new GridBagConstraints();
				gbc_label_3.insets = new Insets(0, 0, 5, 5);
				gbc_label_3.gridx = 3;
				gbc_label_3.gridy = 6;
				add(label_3, gbc_label_3);
		
		lblTelfono = new JLabel("Tel\u00E9fono:");
		lblTelfono.setFont(new Font("Segoe UI", Font.PLAIN, 14));
		GridBagConstraints gbc_lblTelfono = new GridBagConstraints();
		gbc_lblTelfono.anchor = GridBagConstraints.WEST;
		gbc_lblTelfono.insets = new Insets(0, 0, 5, 5);
		gbc_lblTelfono.gridx = 1;
		gbc_lblTelfono.gridy = 7;
		add(lblTelfono, gbc_lblTelfono);
		

		txtTelefono = new JFormattedTextField();
		txtTelefono.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null,
				null, null, null));
		GridBagConstraints gbc_formattedTextField = new GridBagConstraints();
		gbc_formattedTextField.insets = new Insets(0, 0, 5, 5);
		gbc_formattedTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_formattedTextField.gridx = 2;
		gbc_formattedTextField.gridy = 7;
		add(txtTelefono, gbc_formattedTextField);
		
		label_4 = new JLabel("(*)");
		label_4.setFont(new Font("Segoe UI", Font.PLAIN, 14));
		GridBagConstraints gbc_label_4 = new GridBagConstraints();
		gbc_label_4.insets = new Insets(0, 0, 5, 5);
		gbc_label_4.gridx = 3;
		gbc_label_4.gridy = 7;
		add(label_4, gbc_label_4);
		
		lblContrasea = new JLabel("Contrase\u00F1a:");
		lblContrasea.setFont(new Font("Segoe UI", Font.PLAIN, 14));
		GridBagConstraints gbc_lblContrasea = new GridBagConstraints();
		gbc_lblContrasea.anchor = GridBagConstraints.WEST;
		gbc_lblContrasea.insets = new Insets(0, 0, 5, 5);
		gbc_lblContrasea.gridx = 1;
		gbc_lblContrasea.gridy = 8;
		add(lblContrasea, gbc_lblContrasea);

		passwordField = new JPasswordField();
		passwordField.setFont(new Font("Segoe UI", Font.PLAIN, 14));
		passwordField.setEchoChar('*');
		passwordField.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null,
				null, null, null));
		GridBagConstraints gbc_passwordField = new GridBagConstraints();
		gbc_passwordField.insets = new Insets(0, 0, 5, 5);
		gbc_passwordField.fill = GridBagConstraints.HORIZONTAL;
		gbc_passwordField.gridx = 2;
		gbc_passwordField.gridy = 8;
		add(passwordField, gbc_passwordField);
		
		label_5 = new JLabel("(*)");
		label_5.setFont(new Font("Segoe UI", Font.PLAIN, 14));
		GridBagConstraints gbc_label_5 = new GridBagConstraints();
		gbc_label_5.insets = new Insets(0, 0, 5, 5);
		gbc_label_5.gridx = 3;
		gbc_label_5.gridy = 8;
		add(label_5, gbc_label_5);
				
				lblRepitaContrasea = new JLabel("Repita contrase\u00F1a:");
				lblRepitaContrasea.setFont(new Font("Segoe UI", Font.PLAIN, 14));
				GridBagConstraints gbc_lblRepitaContrasea = new GridBagConstraints();
				gbc_lblRepitaContrasea.insets = new Insets(0, 0, 5, 5);
				gbc_lblRepitaContrasea.gridx = 1;
				gbc_lblRepitaContrasea.gridy = 9;
				add(lblRepitaContrasea, gbc_lblRepitaContrasea);
				
				passwordField_1 = new JPasswordField();
				passwordField_1.setFont(new Font("Segoe UI", Font.PLAIN, 14));
				passwordField_1.setEchoChar('*');
				passwordField_1.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null,
										null, null, null));
				GridBagConstraints gbc_passwordField_1 = new GridBagConstraints();
				gbc_passwordField_1.insets = new Insets(0, 0, 5, 5);
				gbc_passwordField_1.fill = GridBagConstraints.HORIZONTAL;
				gbc_passwordField_1.gridx = 2;
				gbc_passwordField_1.gridy = 9;
				add(passwordField_1, gbc_passwordField_1);
				
				label_6 = new JLabel("(*)");
				label_6.setFont(new Font("Segoe UI", Font.PLAIN, 14));
				GridBagConstraints gbc_label_6 = new GridBagConstraints();
				gbc_label_6.insets = new Insets(0, 0, 5, 5);
				gbc_label_6.gridx = 3;
				gbc_label_6.gridy = 9;
				add(label_6, gbc_label_6);
		
				panel = new JPanel();
				GridBagConstraints gbc_panel = new GridBagConstraints();
				gbc_panel.anchor = GridBagConstraints.WEST;
				gbc_panel.insets = new Insets(0, 0, 5, 5);
				gbc_panel.fill = GridBagConstraints.VERTICAL;
				gbc_panel.gridx = 2;
				gbc_panel.gridy = 11;
				add(panel, gbc_panel);
				panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
				
						btnVolver = new JButton("< Volver");
						btnVolver.setFont(new Font("Segoe UI", Font.PLAIN, 14));
						btnVolver.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent e) {
								CardLayout cl = (CardLayout) (cardLayout.getLayout());
								cl.show(cardLayout, "panel 2");
							}
						});
						panel.add(btnVolver);
						
								btnRegistrarse = new JButton("Registrarse");
								btnRegistrarse.setFont(new Font("Segoe UI", Font.PLAIN, 14));
								btnRegistrarse.addActionListener(new ActionListener() {
									public void actionPerformed(ActionEvent arg0) {
										registrarUsuario();
									}
								});
								panel.add(btnRegistrarse);
								
								lblCampos = new JLabel("(*) : Campos obligatorios");
								lblCampos.setFont(new Font("Segoe UI", Font.PLAIN, 14));
								GridBagConstraints gbc_lblCampos = new GridBagConstraints();
								gbc_lblCampos.anchor = GridBagConstraints.WEST;
								gbc_lblCampos.insets = new Insets(0, 0, 5, 5);
								gbc_lblCampos.gridx = 2;
								gbc_lblCampos.gridy = 12;
								add(lblCampos, gbc_lblCampos);
	}
	
	private void registrarUsuario(){
		String nombre = txtNombre.getText();
		String a1 = txtA1.getText();
		String a2 = txtA2.getText();
		String correo = txtCorreo.getText();
		String telefono = txtTelefono.getText();
		char[] p1 = passwordField.getPassword();
		char[] p2 = passwordField_1.getPassword();
		
		System.out.println(nombre);
		System.out.println(a1);
		System.out.println(a2);
		System.out.println(correo);
		System.out.println(telefono);
		System.out.println(String.valueOf(p1));
		System.out.println(String.valueOf(p2));
	}

}
